using System;
using System.Globalization;

namespace jSLCore.Client.Presentation.jBinding.BaseConverters
{
    public class jAddTextConverter : jChainConverter
    {
        public AddTextMode Mode { get; set; }
        public string AddText { get; set; }
        public bool EmptyOnNull { get; set; }

        public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
                return EmptyOnNull ? string.Empty : AddText;

            var str = value.ToString();
            
                switch (Mode)
                {
                    case AddTextMode.Prefix:
                        str = AddText + str;
                        break;
                    case AddTextMode.Suffix:
                        str += AddText;
                        break;
                }
                return str;
        }

        public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }

    public enum AddTextMode
    {
        Suffix=0,
        Prefix=1,
    }
}